import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-01
 * Time: 18:05
 */
public class test {
    //把数组按照长度进行排序
    public static void main(String[] args) {
       String[] array = {"aaa","a","aa","aaaa"};

        //匿名内部类形式
        /*Arrays.sort(array, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        });*/

        //Lambda 完整形式
        /*Arrays.sort(array,(String o1, String o2) -> {
                        return o1.length() - o2.length();
                    }
        );*/

        //Lambda 简化形式
        //Comparator为函数式接口，其匿名内部类可进行简化
        Arrays.sort(array, (o1, o2) -> o1.length() - o2.length());

        System.out.println(Arrays.toString(array));
    }
}
